// line 1 "JSONTextWalker.rl"
// line 133 "JSONTextWalker.rl"

/* Note: this file is generated from JSONTextWalker.rl and json.rl. Changes
 * made here will be overwritten when this file is regenerated. */
package com.alkalinesolutions.json.core.impl;

import java.lang.reflect.UndeclaredThrowableException;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;

import com.alkalinesolutions.json.core.DepthExceededException;
import com.alkalinesolutions.json.core.JSONException;
import com.alkalinesolutions.json.core.LengthExceededException;
import com.alkalinesolutions.json.core.Messages;
import com.alkalinesolutions.json.core.SyntaxException;
import com.alkalinesolutions.json.core.impl.JSONEvent.EventType;

/**
 * The parser class for JSON text. Note that per <a
 * href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>, JSON text can only
 * be arrays and objects, and not data types like numbers, booleans, and
 * strings.
 * 
 * @author David Waite &lt;<a href='mailto:david@alkaline-solutions.com'>david@alkaline-solutions.com</a>&gt;
 * 
 */
public class JSONTextWalker implements Iterator<JSONEvent>, Iterable<JSONEvent> {

	/*
	 * stringStart and partialString are used to represent strings while
	 * parsing. Note that numbers are also parsed as strings.
	 */
	private int stringStart;
	private final StringBuilder sb;

	// type and data information for walking the JSON document
	private final Queue<JSONEvent> events;

	private int cs, p, pe, eof, top;
	private int[] stack;
	private char[] data;
	private int maxLength;
	private Object source;
	
	public JSONTextWalker(Object source) {
		if (source == null)
			throw new IllegalArgumentException("source"); //$NON-NLS-1$
                this.source = source;
		
		events = new LinkedList<JSONEvent>();
		sb = new StringBuilder();
		stack = new int[19];
		maxLength = -1;
	}

	private Object getSource() {
		return source;
	}
	/**
	 * Set the maximum stack depth. Default is 19 (19 nested levels, for 20
	 * total).
	 */
	public void setStackDepth(final int depth) {
		stack = new int[depth];
	}

	/** Get the maximum stack depth. */
	public int getStackDepth() {
		return stack.length;
	}

	/**
	 * Set the maximum length of JSON text to allow, in characters. Default is
	 * <code>-1</code>, which will allow any size JSON text to be parsed.
	 */
	public void setMaxLength(final int maxLength) {
		this.maxLength = maxLength;
	}

	/**
	 * Get the maximum length of JSON text allowed, in characters. The special
	 * value <code>-1</code> indicates any length is allowed.
	 */
	public int getMaxLength() {
		return maxLength;
	}

	private void clearStringBuffer() {
		sb.delete(0, sb.length());
	}

	private void appendEscapedChar(final char ch) {
		sb.append(data, stringStart, p - stringStart - 1);
		stringStart = p + 1;
		sb.append(ch);
	}


// line 104 "JSONTextWalker.java"
private static byte[] init__JSON_actions_0()
{
	return new byte [] {
	    0,    1,    0,    1,    1,    1,    2,    1,    3,    1,    4,    1,
	    5,    1,    6,    1,    7,    1,    8,    1,    9,    1,   10,    1,
	   11,    1,   12,    1,   13,    1,   14,    1,   15,    1,   16,    1,
	   17,    1,   18,    1,   19,    1,   20,    1,   24,    1,   25,    2,
	   20,    6,    2,   20,    9,    2,   20,   24,    2,   20,   25,    2,
	   21,    4,    2,   22,   27,    2,   23,   26,    3,   10,   22,   27,
	    3,   10,   23,   26,    3,   20,   22,   27,    3,   21,   23,   26
	};
}

private static final byte _JSON_actions[] = init__JSON_actions_0();


private static short[] init__JSON_key_offsets_0()
{
	return new short [] {
	    0,    0,    6,   12,   16,   21,   35,   39,   45,   50,   59,   65,
	   71,   77,   83,   86,   95,   97,  107,  111,  113,  121,  132,  133,
	  134,  135,  136,  137,  138,  139,  140,  141,  142,  151,  157,  163,
	  169,  175,  190,  194,  200,  214,  217,  226,  228,  238,  242,  244,
	  252,  263,  264,  265,  266,  267,  268,  269,  270,  271,  272,  273,
	  282,  288,  294,  300,  306,  310,  310
	};
}

private static final short _JSON_key_offsets[] = init__JSON_key_offsets_0();


private static int[] init__JSON_trans_keys_0()
{
	return new int [] {
	   13,   32,   91,  123,    9,   10,   13,   32,   34,  125,    9,   10,
	   34,   92,   32,65535,   13,   32,   58,    9,   10,   13,   32,   34,
	   45,   48,   91,  102,  110,  116,  123,    9,   10,   49,   57,   34,
	   92,   32,65535,   13,   32,   44,  125,    9,   10,   13,   32,   34,
	    9,   10,   34,   47,   92,   98,  102,  110,  114,  116,  117,   48,
	   57,   65,   70,   97,  102,   48,   57,   65,   70,   97,  102,   48,
	   57,   65,   70,   97,  102,   48,   57,   65,   70,   97,  102,   48,
	   49,   57,   13,   32,   44,   46,   69,  101,  125,    9,   10,   48,
	   57,   13,   32,   44,   69,  101,  125,    9,   10,   48,   57,   43,
	   45,   48,   57,   48,   57,   13,   32,   44,  125,    9,   10,   48,
	   57,   13,   32,   44,   46,   69,  101,  125,    9,   10,   48,   57,
	   97,  108,  115,  101,  117,  108,  108,  114,  117,  101,   34,   47,
	   92,   98,  102,  110,  114,  116,  117,   48,   57,   65,   70,   97,
	  102,   48,   57,   65,   70,   97,  102,   48,   57,   65,   70,   97,
	  102,   48,   57,   65,   70,   97,  102,   13,   32,   34,   45,   48,
	   91,   93,  102,  110,  116,  123,    9,   10,   49,   57,   34,   92,
	   32,65535,   13,   32,   44,   93,    9,   10,   13,   32,   34,   45,
	   48,   91,  102,  110,  116,  123,    9,   10,   49,   57,   48,   49,
	   57,   13,   32,   44,   46,   69,   93,  101,    9,   10,   48,   57,
	   13,   32,   44,   69,   93,  101,    9,   10,   48,   57,   43,   45,
	   48,   57,   48,   57,   13,   32,   44,   93,    9,   10,   48,   57,
	   13,   32,   44,   46,   69,   93,  101,    9,   10,   48,   57,   97,
	  108,  115,  101,  117,  108,  108,  114,  117,  101,   34,   47,   92,
	   98,  102,  110,  114,  116,  117,   48,   57,   65,   70,   97,  102,
	   48,   57,   65,   70,   97,  102,   48,   57,   65,   70,   97,  102,
	   48,   57,   65,   70,   97,  102,   13,   32,    9,   10,    0
	};
}

private static final int _JSON_trans_keys[] = init__JSON_trans_keys_0();


private static byte[] init__JSON_single_lengths_0()
{
	return new byte [] {
	    0,    4,    4,    2,    3,   10,    2,    4,    3,    9,    0,    0,
	    0,    0,    1,    7,    0,    6,    2,    0,    4,    7,    1,    1,
	    1,    1,    1,    1,    1,    1,    1,    1,    9,    0,    0,    0,
	    0,   11,    2,    4,   10,    1,    7,    0,    6,    2,    0,    4,
	    7,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    9,
	    0,    0,    0,    0,    2,    0,    0
	};
}

private static final byte _JSON_single_lengths[] = init__JSON_single_lengths_0();


private static byte[] init__JSON_range_lengths_0()
{
	return new byte [] {
	    0,    1,    1,    1,    1,    2,    1,    1,    1,    0,    3,    3,
	    3,    3,    1,    1,    1,    2,    1,    1,    2,    2,    0,    0,
	    0,    0,    0,    0,    0,    0,    0,    0,    0,    3,    3,    3,
	    3,    2,    1,    1,    2,    1,    1,    1,    2,    1,    1,    2,
	    2,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
	    3,    3,    3,    3,    1,    0,    0
	};
}

private static final byte _JSON_range_lengths[] = init__JSON_range_lengths_0();


private static short[] init__JSON_index_offsets_0()
{
	return new short [] {
	    0,    0,    6,   12,   16,   21,   34,   38,   44,   49,   59,   63,
	   67,   71,   75,   78,   87,   89,   98,  102,  104,  111,  121,  123,
	  125,  127,  129,  131,  133,  135,  137,  139,  141,  151,  155,  159,
	  163,  167,  181,  185,  191,  204,  207,  216,  218,  227,  231,  233,
	  240,  250,  252,  254,  256,  258,  260,  262,  264,  266,  268,  270,
	  280,  284,  288,  292,  296,  300,  301
	};
}

private static final short _JSON_index_offsets[] = init__JSON_index_offsets_0();


private static byte[] init__JSON_trans_targs_wi_0()
{
	return new byte [] {
	    1,    1,   64,   64,    1,    0,    2,    2,    3,   65,    2,    0,
	    4,   32,    3,    0,    4,    4,    5,    4,    0,    5,    5,    6,
	   14,   15,    7,   22,   26,   29,    7,    5,   21,    0,    7,    9,
	    6,    0,    7,    7,    8,   65,    7,    0,    8,    8,    3,    8,
	    0,    6,    6,    6,    6,    6,    6,    6,    6,   10,    0,   11,
	   11,   11,    0,   12,   12,   12,    0,   13,   13,   13,    0,    6,
	    6,    6,    0,   15,   21,    0,    7,    7,    8,   16,   18,   18,
	   65,    7,    0,   17,    0,    7,    7,    8,   18,   18,   65,    7,
	   17,    0,   19,   19,   20,    0,   20,    0,    7,    7,    8,   65,
	    7,   20,    0,    7,    7,    8,   16,   18,   18,   65,    7,   21,
	    0,   23,    0,   24,    0,   25,    0,    7,    0,   27,    0,   28,
	    0,    7,    0,   30,    0,   31,    0,    7,    0,    3,    3,    3,
	    3,    3,    3,    3,    3,   33,    0,   34,   34,   34,    0,   35,
	   35,   35,    0,   36,   36,   36,    0,    3,    3,    3,    0,   37,
	   37,   38,   41,   42,   39,   66,   49,   53,   56,   39,   37,   48,
	    0,   39,   59,   38,    0,   39,   39,   40,   66,   39,    0,   40,
	   40,   38,   41,   42,   39,   49,   53,   56,   39,   40,   48,    0,
	   42,   48,    0,   39,   39,   40,   43,   45,   66,   45,   39,    0,
	   44,    0,   39,   39,   40,   45,   66,   45,   39,   44,    0,   46,
	   46,   47,    0,   47,    0,   39,   39,   40,   66,   39,   47,    0,
	   39,   39,   40,   43,   45,   66,   45,   39,   48,    0,   50,    0,
	   51,    0,   52,    0,   39,    0,   54,    0,   55,    0,   39,    0,
	   57,    0,   58,    0,   39,    0,   38,   38,   38,   38,   38,   38,
	   38,   38,   60,    0,   61,   61,   61,    0,   62,   62,   62,    0,
	   63,   63,   63,    0,   38,   38,   38,    0,   64,   64,   64,    0,
	    0,    0,    0
	};
}

private static final byte _JSON_trans_targs_wi[] = init__JSON_trans_targs_wi_0();


private static byte[] init__JSON_trans_actions_wi_0()
{
	return new byte [] {
	    0,    0,   43,   45,    0,    0,    0,    0,   59,   80,    0,   17,
	   11,    0,    0,   17,    0,    0,    0,    0,   17,    0,    0,   13,
	   19,   19,   43,    0,    0,    0,   45,    0,   19,   17,   15,    0,
	    0,   17,    0,    0,    0,   65,    0,   17,    0,    0,    9,    0,
	   17,   23,   27,   25,   29,   31,   33,   35,   37,    0,   17,    0,
	    0,    0,   17,    0,    0,    0,   17,    0,    0,    0,   17,   39,
	   39,   39,   17,    0,    0,   17,   21,   21,   21,    0,    0,    0,
	   72,   21,   17,    0,   17,   21,   21,   21,    0,    0,   72,   21,
	    0,   17,    0,    0,    0,   17,    0,   17,   21,   21,   21,   72,
	   21,    0,   17,   21,   21,   21,    0,    0,    0,   72,   21,    0,
	   17,    0,   17,    0,   17,    0,   17,    3,   17,    0,   17,    0,
	   17,    5,   17,    0,   17,    0,   17,    7,   17,   23,   27,   25,
	   29,   31,   33,   35,   37,    0,   17,    0,    0,    0,   17,    0,
	    0,    0,   17,    0,    0,    0,   17,   39,   39,   39,   17,    0,
	    0,   47,   50,   50,   53,   76,   41,   41,   41,   56,    0,   50,
	   17,   15,    0,    0,   17,    0,    0,    0,   62,    0,   17,    0,
	    0,   13,   19,   19,   43,    0,    0,    0,   45,    0,   19,   17,
	    0,    0,   17,   21,   21,   21,    0,    0,   68,    0,   21,   17,
	    0,   17,   21,   21,   21,    0,   68,    0,   21,    0,   17,    0,
	    0,    0,   17,    0,   17,   21,   21,   21,   68,   21,    0,   17,
	   21,   21,   21,    0,    0,   68,    0,   21,    0,   17,    0,   17,
	    0,   17,    0,   17,    3,   17,    0,   17,    0,   17,    5,   17,
	    0,   17,    0,   17,    7,   17,   23,   27,   25,   29,   31,   33,
	   35,   37,    0,   17,    0,    0,    0,   17,    0,    0,    0,   17,
	    0,    0,    0,   17,   39,   39,   39,   17,    0,    0,    0,   17,
	   17,   17,    0
	};
}

private static final byte _JSON_trans_actions_wi[] = init__JSON_trans_actions_wi_0();


private static byte[] init__JSON_from_state_actions_0()
{
	return new byte [] {
	    0,    0,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
	    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
	    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
	    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
	    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
	    1,    1,    1,    1,    1,    1,    1
	};
}

private static final byte _JSON_from_state_actions[] = init__JSON_from_state_actions_0();


private static byte[] init__JSON_eof_actions_0()
{
	return new byte [] {
	    0,    0,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
	   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
	   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
	   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
	   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
	   17,   17,   17,   17,    0,    0,    0
	};
}

private static final byte _JSON_eof_actions[] = init__JSON_eof_actions_0();


static final int JSON_start = 1;
static final int JSON_first_final = 64;
static final int JSON_error = 0;

static final int JSON_en_object = 2;
static final int JSON_en_array = 37;
static final int JSON_en_main = 1;

// line 233 "JSONTextWalker.rl"

	/**
	 * Parse JSON text into either an array/list, or object (map).
	 * 
	 * @param value
	 *            structure text to parse
	 * @throws JSONException
	 *             on parsing errors
	 */
	public void loadText(final String value) throws JSONException {
		if ((value == null) || (value.length() == 0))
			throw new IllegalArgumentException("value"); //$NON-NLS-1$

		pe = value.length();
		if ((pe > maxLength) && (maxLength >= 0))
			throw new LengthExceededException(maxLength);

		data = value.toCharArray();
		eof = pe;

		events.clear();

		stringStart = cs = p = top = 0;
		// Generated Initialization Code
		
// line 350 "JSONTextWalker.java"
	{
	cs = JSON_start;
	top = 0;
	}
// line 258 "JSONTextWalker.rl"
	}

	public JSONEvent next() {
		try {
			if (p != pe && events.isEmpty())
				seek();
			return events.remove();
		} catch (final JSONException e) {
			throw new UndeclaredThrowableException(e);
		}
	}

	@SuppressWarnings( { "fallthrough", "cast" })
	private void seek() throws JSONException {
		String key = null;

		if (!events.isEmpty())
			return;

		if (p == eof)
			// Indexing past end of data
			throw new NoSuchElementException(Messages
					.getString("JSONCursor.past-end")); //$NON-NLS-1$
		try {
			// Generated Execution Code
			
// line 382 "JSONTextWalker.java"
	{
	int _klen;
	int _trans = 0;
	int _acts;
	int _nacts;
	int _keys;
	int _goto_targ = 0;

	_goto: while (true) {
	switch ( _goto_targ ) {
	case 0:
	if ( p == pe ) {
		_goto_targ = 4;
		continue _goto;
	}
	if ( cs == 0 ) {
		_goto_targ = 5;
		continue _goto;
	}
case 1:
	_acts = _JSON_from_state_actions[cs];
	_nacts = (int) _JSON_actions[_acts++];
	while ( _nacts-- > 0 ) {
		switch ( _JSON_actions[_acts++] ) {
	case 0:
// line 7 "JSONTextWalker.rl"
	{
		if (!events.isEmpty()) {
			p--;
			{ p += 1; _goto_targ = 5; if (true)  continue _goto;}
		}
	}
	break;
// line 416 "JSONTextWalker.java"
		}
	}

	_match: do {
	_keys = _JSON_key_offsets[cs];
	_trans = _JSON_index_offsets[cs];
	_klen = _JSON_single_lengths[cs];
	if ( _klen > 0 ) {
		int _lower = _keys;
		int _mid;
		int _upper = _keys + _klen - 1;
		while (true) {
			if ( _upper < _lower )
				break;

			_mid = _lower + ((_upper-_lower) >> 1);
			if ( data[p] < _JSON_trans_keys[_mid] )
				_upper = _mid - 1;
			else if ( data[p] > _JSON_trans_keys[_mid] )
				_lower = _mid + 1;
			else {
				_trans += (_mid - _keys);
				break _match;
			}
		}
		_keys += _klen;
		_trans += _klen;
	}

	_klen = _JSON_range_lengths[cs];
	if ( _klen > 0 ) {
		int _lower = _keys;
		int _mid;
		int _upper = _keys + (_klen<<1) - 2;
		while (true) {
			if ( _upper < _lower )
				break;

			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
			if ( data[p] < _JSON_trans_keys[_mid] )
				_upper = _mid - 2;
			else if ( data[p] > _JSON_trans_keys[_mid+1] )
				_lower = _mid + 2;
			else {
				_trans += ((_mid - _keys)>>1);
				break _match;
			}
		}
		_trans += _klen;
	}
	} while (false);

	cs = _JSON_trans_targs_wi[_trans];

	if ( _JSON_trans_actions_wi[_trans] != 0 ) {
		_acts = _JSON_trans_actions_wi[_trans];
		_nacts = (int) _JSON_actions[_acts++];
		while ( _nacts-- > 0 )
	{
			switch ( _JSON_actions[_acts++] )
			{
	case 1:
// line 13 "JSONTextWalker.rl"
	{
		//pushFalse
		events.add(new JSONEvent(getSource(), EventType.Boolean, Boolean.FALSE, key));
	}
	break;
	case 2:
// line 18 "JSONTextWalker.rl"
	{
		//pushNull
		events.add(new JSONEvent(getSource(), EventType.Null, null, key));
	}
	break;
	case 3:
// line 23 "JSONTextWalker.rl"
	{
		//pushTrue
		events.add(new JSONEvent(getSource(), EventType.Boolean, Boolean.TRUE, key));
	}
	break;
	case 4:
// line 28 "JSONTextWalker.rl"
	{
		//startKey
		clearStringBuffer ();
		stringStart = p + 1; // after quote
	}
	break;
	case 5:
// line 33 "JSONTextWalker.rl"
	{
		//pushKey
		// capture into 'key' variable for use by code.
		sb.append(data, stringStart, p - stringStart );
		key = sb.toString();
	}
	break;
	case 6:
// line 39 "JSONTextWalker.rl"
	{
		//startString
		clearStringBuffer ();
		stringStart = p + 1; // after quote
	}
	break;
	case 7:
// line 44 "JSONTextWalker.rl"
	{
		//pushString
		sb.append(data, stringStart, p - stringStart );
		events.add(new JSONEvent(getSource(), EventType.String, sb.toString(), key));
	}
	break;
	case 8:
// line 49 "JSONTextWalker.rl"
	{
		//report
		// error, raise syntax exception
		if (true) throw new SyntaxException(p, cs);
	}
	break;
	case 9:
// line 55 "JSONTextWalker.rl"
	{
		//startNum
		clearStringBuffer ();
		stringStart = p;
	}
	break;
	case 10:
// line 61 "JSONTextWalker.rl"
	{
		//pushNum
		// capture text encountered and store into BigDecimal
		// NOTE: it would be nice to put this into an appropriately sized,
		// integer vs. floating point type.
		sb.append ( data, stringStart, p - stringStart );
		events.add(new JSONEvent(getSource(), EventType.Number, new BigDecimal(sb.toString()), key));
	}
	break;
	case 11:
// line 70 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\"' );
	}
	break;
	case 12:
// line 74 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\\' );
	}
	break;
	case 13:
// line 78 "JSONTextWalker.rl"
	{
		appendEscapedChar( '/' );
	}
	break;
	case 14:
// line 82 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\b' );
	}
	break;
	case 15:
// line 86 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\f' );
	}
	break;
	case 16:
// line 90 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\n' );
	}
	break;
	case 17:
// line 94 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\r' );
	}
	break;
	case 18:
// line 98 "JSONTextWalker.rl"
	{
		appendEscapedChar( '\t' );
	}
	break;
	case 19:
// line 102 "JSONTextWalker.rl"
	{
		// back before \ u x x x x
		sb.append ( data, stringStart, p - stringStart - 5 );
		String point = new String ( data, p - 3, 4 );
		int code = Integer.parseInt ( point, 16 );
		sb.append ( (char) code );
		stringStart = p + 1;
	}
	break;
	case 20:
// line 111 "JSONTextWalker.rl"
	{
    	//startArray
    	events.add(new JSONEvent(getSource(), EventType.StartArray, null, key));
	}
	break;
	case 21:
// line 116 "JSONTextWalker.rl"
	{
    	//startObject
    	events.add(new JSONEvent(getSource(), EventType.StartObject, null, key));
	}
	break;
	case 22:
// line 121 "JSONTextWalker.rl"
	{
		//endArray
		events.add(new JSONEvent(getSource(), EventType.EndArray, null, null));
	}
	break;
	case 23:
// line 126 "JSONTextWalker.rl"
	{
		//endObject
		events.add(new JSONEvent(getSource(), EventType.EndObject, null, null));
	}
	break;
	case 24:
// line 35 "JSONTextWalker.rl"
	{{stack[top++] = cs; cs = 37; _goto_targ = 2; if (true) continue _goto;}}
	break;
	case 25:
// line 36 "JSONTextWalker.rl"
	{{stack[top++] = cs; cs = 2; _goto_targ = 2; if (true) continue _goto;}}
	break;
	case 26:
// line 45 "JSONTextWalker.rl"
	{{cs = stack[--top];_goto_targ = 2; if (true) continue _goto;}}
	break;
	case 27:
// line 46 "JSONTextWalker.rl"
	{{cs = stack[--top];_goto_targ = 2; if (true) continue _goto;}}
	break;
// line 662 "JSONTextWalker.java"
			}
		}
	}

case 2:
	if ( cs == 0 ) {
		_goto_targ = 5;
		continue _goto;
	}
	if ( ++p != pe ) {
		_goto_targ = 1;
		continue _goto;
	}
case 4:
	if ( p == eof )
	{
	int __acts = _JSON_eof_actions[cs];
	int __nacts = (int) _JSON_actions[__acts++];
	while ( __nacts-- > 0 ) {
		switch ( _JSON_actions[__acts++] ) {
	case 8:
// line 49 "JSONTextWalker.rl"
	{
		//report
		// error, raise syntax exception
		if (true) throw new SyntaxException(p, cs);
	}
	break;
// line 691 "JSONTextWalker.java"
		}
	}
	}

case 5:
	}
	break; }
	}
// line 284 "JSONTextWalker.rl"
		} catch (final ArrayIndexOutOfBoundsException e) {
			if (top >= stack.length)
				throw new DepthExceededException(p, top);
			throw e;
		}
	}

	public Iterator<JSONEvent> iterator() {
		return this;
	}

	public boolean hasNext() {
		if (!events.isEmpty()) return true;
		if (p == pe) return false;
		try {
			seek();
		}
		catch (Exception e) {
			throw new UndeclaredThrowableException(e);
		}
		return (!events.isEmpty());
	}

	public void remove() {
		throw new UnsupportedOperationException();
	}
}
